/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainFrame.java
 *
 * Created on Jan 19, 2013, 10:52:57 AM
 */
package com.datamining.gui;

import com.algo.frequentpatterns.apriori_optimized.Itemset;
import com.datamining.api.Facad;
import com.datamining.gui.Constants.Algorithm;
import com.datamining.gui.Constants.ChartType;
import com.itextpdf.awt.DefaultFontMapper;
import com.itextpdf.awt.PdfGraphics2D;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfTemplate;
import com.itextpdf.text.pdf.PdfWriter;
import java.awt.BorderLayout;
import java.awt.Graphics2D;
import java.awt.SplashScreen;
import java.awt.geom.Rectangle2D;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.filechooser.FileFilter;
import javax.swing.table.DefaultTableModel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.util.Rotation;
import org.jpedal.PdfDecoder;
import com.datamining.gui.About;

/**
 *
 * @author Challiz
 */
public class MainFrame extends javax.swing.JFrame {

    /** Creates new form MainFrame */
    public MainFrame() {
        renderSplashScreen();
        initComponents();
        initMyComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel2 = new javax.swing.JPanel();
        chartTypeComboBox = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        algorithmComboBox = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        titleTextField = new GUITextBox();
        xNameTextField = new GUITextBox();
        yNameTextField = new GUITextBox();
        goButton = new javax.swing.JButton();
        varLabel = new javax.swing.JLabel();
        varTextField = new javax.swing.JTextField();
        jToolBar1 = new javax.swing.JToolBar();
        csvButton = new javax.swing.JButton();
        bdfButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        pieChartViewButton = new javax.swing.JButton();
        barChartViewButton = new javax.swing.JButton();
        tableViewButton = new javax.swing.JButton();
        reportViewButton = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        exitMenuItem = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenuItem9 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("STANA");
        setIconImage(new ImageIcon(getClass().getResource("/com/datamining/gui/img/stanalogo32.png")).getImage());
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                windowClosingActionPerformed(evt);
            }
        });

        jPanel1.setMinimumSize(new java.awt.Dimension(103, 35));
        jPanel1.setPreferredSize(new java.awt.Dimension(252, 400));

        jSplitPane1.setDividerLocation(150);
        jSplitPane1.setDividerSize(2);
        jSplitPane1.setFocusable(false);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Configurations"));
        jPanel2.setPreferredSize(new java.awt.Dimension(149, 399));

        chartTypeComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chartTypeComboBoxActionPerformed(evt);
            }
        });

        jLabel1.setText("Select Chart:");

        jLabel2.setText("Select Algorithm:");

        algorithmComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                algorithmComboBoxActionPerformed(evt);
            }
        });

        jLabel3.setText("Chart Configurations:");

        titleTextField.setForeground(new java.awt.Color(204, 204, 204));
        titleTextField.setText("Enter Title");
        titleTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                titleTextFieldKeyTyped(evt);
            }
        });

        xNameTextField.setForeground(new java.awt.Color(204, 204, 204));
        xNameTextField.setText("Enter X-Axis Name");
        xNameTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                xNameTextFieldKeyTyped(evt);
            }
        });

        yNameTextField.setForeground(new java.awt.Color(204, 204, 204));
        yNameTextField.setText("Enter Y-Axis Name");
        yNameTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                yNameTextFieldKeyTyped(evt);
            }
        });

        goButton.setText("Go");
        goButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                goButtonActionPerformed(evt);
            }
        });

        varLabel.setText("Number of clusters:");

        varTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                varTextFieldKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                    .addComponent(chartTypeComboBox, javax.swing.GroupLayout.Alignment.TRAILING, 0, 127, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                    .addComponent(algorithmComboBox, 0, 127, Short.MAX_VALUE)
                    .addComponent(goButton, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                    .addComponent(titleTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                    .addComponent(xNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                    .addComponent(yNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                    .addComponent(varLabel)
                    .addComponent(varTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(chartTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addComponent(algorithmComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(varLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(varTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(titleTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(xNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(yNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addComponent(goButton, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 11, Short.MAX_VALUE))
        );

        jSplitPane1.setLeftComponent(jPanel2);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 749, Short.MAX_VALUE)
                .addGap(180, 180, 180))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 401, Short.MAX_VALUE))
        );

        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 757, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(4, 4, 4)
                    .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 749, Short.MAX_VALUE)
                    .addGap(4, 4, 4)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 406, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE)
                    .addContainerGap()))
        );

        jToolBar1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        csvButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/datamining/gui/img/csv_file.png"))); // NOI18N
        csvButton.setToolTipText("Read CSV File");
        csvButton.setFocusable(false);
        csvButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        csvButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        csvButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                csvButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(csvButton);

        bdfButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/datamining/gui/img/bdf_file.jpg"))); // NOI18N
        bdfButton.setToolTipText("Read BDF File");
        bdfButton.setFocusable(false);
        bdfButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bdfButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bdfButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bdfButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(bdfButton);

        saveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/datamining/gui/img/save_icon.png"))); // NOI18N
        saveButton.setToolTipText("Save As PDF File");
        saveButton.setFocusable(false);
        saveButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        saveButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(saveButton);

        pieChartViewButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/datamining/gui/img/pie_chart.jpg"))); // NOI18N
        pieChartViewButton.setToolTipText("View Pie Chart");
        pieChartViewButton.setFocusable(false);
        pieChartViewButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        pieChartViewButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        pieChartViewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pieChartViewButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(pieChartViewButton);

        barChartViewButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/datamining/gui/img/imagem-28.jpg"))); // NOI18N
        barChartViewButton.setToolTipText("View Bar Chart");
        barChartViewButton.setFocusable(false);
        barChartViewButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        barChartViewButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        barChartViewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                barChartViewButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(barChartViewButton);

        tableViewButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/datamining/gui/img/table32.png"))); // NOI18N
        tableViewButton.setToolTipText("Table View");
        tableViewButton.setFocusable(false);
        tableViewButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tableViewButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        tableViewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tableViewButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(tableViewButton);

        reportViewButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/datamining/gui/img/report32.png"))); // NOI18N
        reportViewButton.setToolTipText("View Report");
        reportViewButton.setFocusable(false);
        reportViewButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        reportViewButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        reportViewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reportViewButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(reportViewButton);

        jMenu1.setMnemonic('f');
        jMenu1.setText("File");

        jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/datamining/gui/img/csv16.png"))); // NOI18N
        jMenuItem1.setMnemonic('v');
        jMenuItem1.setText("Import CSV");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/datamining/gui/img/dbf16.png"))); // NOI18N
        jMenuItem2.setMnemonic('d');
        jMenuItem2.setText("Import DBF");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/datamining/gui/img/save16.png"))); // NOI18N
        jMenuItem3.setMnemonic('s');
        jMenuItem3.setText("Save As PDF");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);
        jMenu1.add(jSeparator1);

        exitMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/datamining/gui/img/close.png"))); // NOI18N
        exitMenuItem.setMnemonic('x');
        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(exitMenuItem);

        jMenuBar1.add(jMenu1);

        jMenu2.setMnemonic('v');
        jMenu2.setText("View");

        jMenuItem4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/datamining/gui/img/table16.png"))); // NOI18N
        jMenuItem4.setMnemonic('t');
        jMenuItem4.setText("Table View");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem4);

        jMenuItem5.setMnemonic('p');
        jMenuItem5.setText("Pie Chart View");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem5);

        jMenuItem6.setMnemonic('b');
        jMenuItem6.setText("Bar Chart View");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem6);

        jMenuItem7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/datamining/gui/img/report16.png"))); // NOI18N
        jMenuItem7.setMnemonic('r');
        jMenuItem7.setText("Report View");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem7);

        jMenuBar1.add(jMenu2);

        jMenu3.setMnemonic('h');
        jMenu3.setText("Help");

        jMenuItem8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/datamining/gui/img/help16.png"))); // NOI18N
        jMenuItem8.setMnemonic('u');
        jMenuItem8.setText("STANA Tutorial");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem8);

        jMenuItem9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/datamining/gui/img/about16.png"))); // NOI18N
        jMenuItem9.setMnemonic('a');
        jMenuItem9.setText("About STANA");
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMenuItem9ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem9);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 939, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 939, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(411, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addGap(48, 48, 48)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 406, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt){//GEN-FIRST:event_exitMenuItemActionPerformed
       int ans = JOptionPane.showConfirmDialog(this, "Are you sure you want to exit STANA?", "EXIT STANA",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
        if (ans==0){ this.dispose();}
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void goButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goButtonActionPerformed
        drawChart((ChartType) chartTypeComboBox.getSelectedItem(), (Algorithm) algorithmComboBox.getSelectedItem(), titleTextField.getText(), xNameTextField.getText(), yNameTextField.getText());
    }//GEN-LAST:event_goButtonActionPerformed

    private void algorithmComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_algorithmComboBoxActionPerformed
        if (((Algorithm) algorithmComboBox.getSelectedItem()) == Algorithm.Apriori) {
            varLabel.setText("Min Support:");
        } else {
            varLabel.setText("Number of clusters:");
        }
        drawnChart = null;
    }//GEN-LAST:event_algorithmComboBoxActionPerformed

    private void csvButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_csvButtonActionPerformed
        JFileChooser chooser = new JFileChooser();
        chooser.setMultiSelectionEnabled(false);
        chooser.setFileFilter(new FileFilter() {

            @Override
            public boolean accept(File f) {
                return f.isDirectory() || f.getName().toLowerCase().endsWith(".csv");
            }

            @Override
            public String getDescription() {
                return "CSV Files (*.csv)";
            }
        });
        int result = chooser.showOpenDialog(this);
        if (result != JFileChooser.CANCEL_OPTION) {
            File file = chooser.getSelectedFile();
            facad.readDataSet(file.getPath());
            c=1;
            tableViewButtonActionPerformed(evt);
            jPanel1.setVisible(true);
        }
    }//GEN-LAST:event_csvButtonActionPerformed

    private void bdfButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bdfButtonActionPerformed
        JFileChooser chooser = new JFileChooser();
        chooser.setMultiSelectionEnabled(false);
        chooser.setFileFilter(new FileFilter() {

            @Override
            public boolean accept(File f) {
                return f.isDirectory() || f.getName().toLowerCase().endsWith(".dbf");
            }

            @Override
            public String getDescription() {
                return "DBF Files (*.dbf)";
            }
        });
        int result = chooser.showOpenDialog(this);
        if (result != JFileChooser.CANCEL_OPTION) {
            File file = chooser.getSelectedFile();
            facad.setFile(file);
            facad.readDataSet(file.getPath());
            c=1;
            tableViewButtonActionPerformed(evt);
            jPanel1.setVisible(true);
        }
    }//GEN-LAST:event_bdfButtonActionPerformed

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        printPdfChart((ChartType) chartTypeComboBox.getSelectedItem(), (Algorithm) algorithmComboBox.getSelectedItem(), titleTextField.getText(), xNameTextField.getText(), yNameTextField.getText());
    }//GEN-LAST:event_saveButtonActionPerformed

    private void tableViewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tableViewButtonActionPerformed
     if (c==0){
          JOptionPane.showMessageDialog(this, "Please import a file first.", "Error", JOptionPane.INFORMATION_MESSAGE);
       }
     else{
         JPanel topPanel = new JPanel();

        topPanel.setLayout(new BorderLayout());
        getContentPane().add(topPanel);

        JTable table = new JTable(new DefaultTableModel(toStringArray(facad.getDataSet()), Facad.getTableHeader()) {

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }
        });

        table.getCellEditor();
        JScrollPane scrollPane = new JScrollPane(table);
        topPanel.add(scrollPane, BorderLayout.CENTER);
        jSplitPane1.setRightComponent(topPanel);
        jPanel1.setVisible(true);
        }
    }//GEN-LAST:event_tableViewButtonActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        csvButtonActionPerformed(evt);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        bdfButtonActionPerformed(evt);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        saveButtonActionPerformed(evt);
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        tableViewButtonActionPerformed(evt);
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void chartTypeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chartTypeComboBoxActionPerformed
        drawnChart = null;
    }//GEN-LAST:event_chartTypeComboBoxActionPerformed

    private void varTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_varTextFieldKeyTyped
        drawnChart = null;
    }//GEN-LAST:event_varTextFieldKeyTyped

    private void titleTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_titleTextFieldKeyTyped
        drawnChart = null;
    }//GEN-LAST:event_titleTextFieldKeyTyped

    private void xNameTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_xNameTextFieldKeyTyped
        drawnChart = null;
    }//GEN-LAST:event_xNameTextFieldKeyTyped

    private void yNameTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_yNameTextFieldKeyTyped
        drawnChart = null;
    }//GEN-LAST:event_yNameTextFieldKeyTyped

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        chartTypeComboBox.setSelectedItem(ChartType.Pie_Chart);
        drawChart(ChartType.Pie_Chart, (Algorithm) algorithmComboBox.getSelectedItem(), titleTextField.getText(), xNameTextField.getText(), yNameTextField.getText());
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
        chartTypeComboBox.setSelectedItem(ChartType.Bar_Chart);
        drawChart(ChartType.Bar_Chart, (Algorithm) algorithmComboBox.getSelectedItem(), titleTextField.getText(), xNameTextField.getText(), yNameTextField.getText());
    }//GEN-LAST:event_jMenuItem6ActionPerformed

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
        reportViewButtonActionPerformed(evt);
    }//GEN-LAST:event_jMenuItem7ActionPerformed

    private void pieChartViewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pieChartViewButtonActionPerformed
        chartTypeComboBox.setSelectedItem(ChartType.Pie_Chart);
        drawChart(ChartType.Pie_Chart, (Algorithm) algorithmComboBox.getSelectedItem(), titleTextField.getText(), xNameTextField.getText(), yNameTextField.getText());
    }//GEN-LAST:event_pieChartViewButtonActionPerformed

    private void barChartViewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_barChartViewButtonActionPerformed
        chartTypeComboBox.setSelectedItem(ChartType.Bar_Chart);
        drawChart(ChartType.Bar_Chart, (Algorithm) algorithmComboBox.getSelectedItem(), titleTextField.getText(), xNameTextField.getText(), yNameTextField.getText());
    }//GEN-LAST:event_barChartViewButtonActionPerformed

    private void reportViewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reportViewButtonActionPerformed
        Algorithm algorithm = (Algorithm) algorithmComboBox.getSelectedItem();
        ChartType chartType = (ChartType) chartTypeComboBox.getSelectedItem();
        String chartTitle = titleTextField.getText();
        String xAxisName = xNameTextField.getText();
        String yAxisName = yNameTextField.getText();
        FileOutputStream fileStream;
        try {
            double num = Double.parseDouble(varTextField.getText());
            if (drawnChart == null) {
                HashMap results = getAlgorithmResults(algorithm, num);
                drawnChart = createChart(chartType, results, chartTitle, xAxisName, yAxisName);
            }
            String report = getReport(algorithm);
            ByteArrayOutputStream pdfStream = generatePdf(drawnChart, report, algorithm, chartTitle);
            fileStream = new FileOutputStream(System.getProperty("java.io.tmpdir") + "\\tempChart.pdf");
            pdfStream.writeTo(fileStream);
            pdfStream.flush();
            pdfStream.close();

            PdfDecoder pdfPanel = new PdfDecoder();
            pdfPanel.openPdfFile(System.getProperty("java.io.tmpdir") + "\\tempChart.pdf");
            pdfPanel.decodePage(1);
            pdfPanel.setPageParameters(1, 1); //values scaling (1=100%). page number
            pdfPanel.invalidate();
            JScrollPane scroll = new JScrollPane(pdfPanel);
            jSplitPane1.setRightComponent(scroll);
        } catch (NumberFormatException ex) {
            String message = (varTextField.getText().equals("")) ? "Please enter a number!!" : varTextField.getText() + " is not a number!!";
            JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "The following error occured: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_reportViewButtonActionPerformed

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
        // TODO add your handling code here:
         Runtime run = Runtime.getRuntime();
            try
            {
            Process child = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler \\STANA\\src\\com\\datamining\\gui\\img\\stanahelp.chm");
            }
            catch (Exception ex)
            {
            ex.printStackTrace();
            System.out.println(ex.getMessage());
            }
    }//GEN-LAST:event_jMenuItem8ActionPerformed

    private void windowClosingActionPerformed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_windowClosingActionPerformed
        // TODO add your handling code here:
        int ans = JOptionPane.showConfirmDialog(this, "Are you sure you want to exit STANA?", "EXIT STANA",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
        if (ans==0){ this.dispose();}
    }//GEN-LAST:event_windowClosingActionPerformed

    private void JMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMenuItem9ActionPerformed
        // TODO add your handling code here:
        About abt = new About(null,true);
        abt.setVisible(true);
    }//GEN-LAST:event_JMenuItem9ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox algorithmComboBox;
    private javax.swing.JButton barChartViewButton;
    private javax.swing.JButton bdfButton;
    private javax.swing.JComboBox chartTypeComboBox;
    private javax.swing.JButton csvButton;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JButton goButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JButton pieChartViewButton;
    private javax.swing.JButton reportViewButton;
    private javax.swing.JButton saveButton;
    private javax.swing.JButton tableViewButton;
    private javax.swing.JTextField titleTextField;
    private javax.swing.JLabel varLabel;
    private javax.swing.JTextField varTextField;
    private javax.swing.JTextField xNameTextField;
    private javax.swing.JTextField yNameTextField;
    // End of variables declaration//GEN-END:variables
    private int c;
    private Facad facad;
    private JFreeChart drawnChart = null;
    private final String columnNames[] = {"#", "Transaction", "Barcode", "Item Description", "Quantity", "Price", "Date Purchased"};

    private JFreeChart createChart(ChartType chartType, HashMap data, String chartTitle, String xAxisName, String yAxisName) {
        JFreeChart chart;
        if (chartType == ChartType.Bar_Chart) {
            chart = createBarChart(data, chartTitle, xAxisName, yAxisName);
        } else {
            chart = createPieChart(data, chartTitle, xAxisName, yAxisName);
        }

        return chart;
    }

    private JFreeChart createBarChart(HashMap data, String chartTitle, String xAxisName, String yAxisName) {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for (Object key : data.keySet()) {
            dataset.addValue((Integer) data.get(key), (String) key, "");
        }

        JFreeChart chart = ChartFactory.createBarChart3D(chartTitle, xAxisName, yAxisName, dataset, PlotOrientation.VERTICAL, true, true, false);
        CategoryPlot localCategoryPlot = (CategoryPlot) chart.getPlot();
        localCategoryPlot.setOutlineVisible(false);
        localCategoryPlot.setDomainGridlinesVisible(true);
        CategoryAxis localCategoryAxis = localCategoryPlot.getDomainAxis();
        localCategoryAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.3926990816987241D));
        localCategoryAxis.setCategoryMargin(0.0D);
        BarRenderer3D localBarRenderer3D = (BarRenderer3D) localCategoryPlot.getRenderer();
        localBarRenderer3D.setDrawBarOutline(false);
        return chart;
    }

    private JFreeChart createPieChart(HashMap data, String chartTitle, String xAxisName, String yAxisName) {
        DefaultPieDataset dataset = new DefaultPieDataset();
        for (Object key : data.keySet()) {
            dataset.setValue((String) key, (Integer) data.get(key));
        }

        JFreeChart chart = ChartFactory.createPieChart3D(chartTitle, dataset, true, true, false);
        PiePlot3D plot3D = (PiePlot3D) chart.getPlot();
        plot3D.setDarkerSides(true);
        plot3D.setStartAngle(290.0D);
        plot3D.setDirection(Rotation.CLOCKWISE);
        plot3D.setForegroundAlpha(1.0F);
        plot3D.setNoDataMessage("No data to display");
        return chart;
    }

    private JFreeChart getChart(ChartType chartType, Algorithm algorithm, double num, String chartTitle, String xAxisName, String yAxisName) {
        HashMap results = getAlgorithmResults(algorithm, num);
        return createChart(chartType, results, chartTitle, xAxisName, yAxisName);
    }

    private void drawChart(ChartType chartType, Algorithm algorithm, String chartTitle, String xAxisName, String yAxisName) {
        try {
            double num = Double.parseDouble(varTextField.getText());
            drawnChart = getChart(chartType, algorithm, num, chartTitle, xAxisName, yAxisName);
            ChartPanel panel = new ChartPanel(drawnChart);
            jSplitPane1.setRightComponent(panel);
        } catch (NumberFormatException ex) {
            String message = (varTextField.getText().equals("")) ? "Please enter a number!!" : varTextField.getText() + " is not a number!!";
            JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    private HashMap getAlgorithmResults(Algorithm algorithm, double number) {
        HashMap map = new HashMap();
        int index = 1;
        if (algorithm == Algorithm.Apriori) {
            ArrayList<Itemset> items = facad.applyApriori(number);
            for (Itemset item : items) {
                map.put(item.toString() + " [" + item.count + "]", new Integer(item.count));
            }
        } else {
            List<com.algo.clustering.kmeans.Cluster> clusters = facad.applyKmeans(new Double(number).intValue());
            for (com.algo.clustering.kmeans.Cluster cluster : clusters) {
                map.put(cluster.toString(), new Integer(cluster.getVectors().size()));
            }
        }

        return map;
    }

    private void initMyComponents() {
        chartTypeComboBox.addItem(ChartType.Pie_Chart);
        chartTypeComboBox.addItem(ChartType.Bar_Chart);

        algorithmComboBox.addItem(Algorithm.K_Means);
        algorithmComboBox.addItem(Algorithm.Apriori);

        ((GUITextBox) titleTextField).setFieldName("Title");
        ((GUITextBox) xNameTextField).setFieldName("X-Axis Name");
        ((GUITextBox) yNameTextField).setFieldName("Y-Axis Name");

        setExtendedState(MAXIMIZED_BOTH);
        jPanel1.setVisible(false);
        facad = new Facad();

    }

    private void printPdfChart(ChartType chartType, Algorithm algorithm, String chartTitle, String xAxisName, String yAxisName) {
        FileOutputStream fileStream = null;
        try {
            double num = Double.parseDouble(varTextField.getText());
            if (drawnChart == null) {
                HashMap results = getAlgorithmResults(algorithm, num);
                drawnChart = createChart(chartType, results, chartTitle, xAxisName, yAxisName);
            }
            String report = getReport(algorithm);
            ByteArrayOutputStream pdfStream = generatePdf(drawnChart, report, algorithm, chartTitle);
            JFileChooser savePdf = new JFileChooser();
            savePdf.setMultiSelectionEnabled(false);
            savePdf.setFileFilter(new FileFilter() {

                @Override
                public boolean accept(File f) {
                    return f.isDirectory() || f.getName().toLowerCase().endsWith(".pdf");
                }

                @Override
                public String getDescription() {
                    return "Pdf Files (*.pdf)";
                }
            });

            int result = savePdf.showSaveDialog(this);
            if (result != JFileChooser.CANCEL_OPTION) {
                File file = savePdf.getSelectedFile();
                int yesOrNo = JOptionPane.YES_OPTION;
                if (file.exists()) {
                    yesOrNo = JOptionPane.showConfirmDialog(savePdf, "File already exists. Overwrite?", "File Exsits", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                }
                if (yesOrNo == JOptionPane.YES_OPTION) {
                    String filePath = file.getPath();
                    filePath = filePath.endsWith(".pdf") ? filePath : filePath + ".pdf";
                    fileStream = new FileOutputStream(filePath);
                    pdfStream.writeTo(fileStream);
                    jPanel1.setVisible(true);
                }
            }
        } catch (NumberFormatException ex) {
            String message = (varTextField.getText().equals("")) ? "Please enter a number!!" : varTextField.getText() + " is not a number!!";
            JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "The following error occured: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        } finally {
            if (fileStream != null) {
                try {
                    fileStream.flush();
                    fileStream.close();
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(this, "The following error occured: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    }

    private ByteArrayOutputStream generatePdf(JFreeChart chart, String report, Algorithm algorithm, String chartTitle) throws Exception {
        Document doc = new Document();
        ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
        PdfWriter docWriter = null;

        try {
            docWriter = PdfWriter.getInstance(doc, baosPDF);

            doc.addProducer();
            doc.addCreator(this.getClass().getName());
            doc.addTitle(chartTitle + " using " + algorithm + " algorithm");
            doc.setPageSize(PageSize.A4);

            doc.open();
            doc.add(new Phrase(report));
            int width = 260;
            int height = 250;

            // get the direct pdf content
            PdfContentByte dc = docWriter.getDirectContent();

            // get a pdf template from the direct content
            PdfTemplate tp = dc.createTemplate(width, height);

            // create an AWT renderer from the pdf template
            Graphics2D g2 = new PdfGraphics2D(tp, width, height, new DefaultFontMapper());
            //Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper());
            Rectangle2D r2D = new Rectangle2D.Double(0, 0, width, height);
            chart.draw(g2, r2D);
            g2.dispose();

            // add the rendered pdf template to the direct content
            // you will have to play around with this because the chart is absolutely positioned.
            // 38 is just a typical left margin
            // docWriter.getVerticalPosition(true) will approximate the position that the content above the chart ended
            dc.addTemplate(tp, 38, docWriter.getVerticalPosition(true) - height);
        } catch (DocumentException dex) {
            baosPDF.reset();
            dex.printStackTrace();
            throw new DocumentException(dex);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            if (doc != null && doc.isOpen()) {
                doc.close();
            }
            if (docWriter != null) {
                docWriter.close();
            }
        }

        if (baosPDF.size() < 1) {
            throw new DocumentException("document has " + baosPDF.size() + " bytes");
        }
        return baosPDF;
    }

    private String getReport(Algorithm algorithm) {
        if (algorithm == Algorithm.Apriori) {
            return facad.getAprioriReport();
        }

        return facad.getKmeansReport();
    }

    private String[][] toStringArray(ArrayList<ArrayList<String>> data) {
        if(data.isEmpty())
            return new String[0][0];
        String[][] dataValues = new String[data.size()][data.get(0).size()];
        for (int i = 0; i < data.size(); ++i) {
            List<String> row = data.get(i);
            for (int j = 0; j < row.size(); ++j) {
                dataValues[i][j] = row.get(j);
            }
        }
        return dataValues;
    }

    private void renderSplashScreen() {
        final SplashScreen splash = SplashScreen.getSplashScreen();
        if (splash == null) {
            System.out.println("SplashScreen.getSplashScreen() returned null");
            return;
        }
        Graphics2D g = splash.createGraphics();
        if (g == null) {
            System.out.println("g is null");
            return;
        }
        for (int i = 0; i < 100; i++) {
            splash.update();
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
            }
        }
        splash.close();
    }
}
